home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!j-bg.demon.co.uk
- From: John Sargent <jb@j-bg.demon.co.uk>
- Newsgroups: comp.lang.c++
- Subject: Re: Array pointer?
- Date: Sun, 14 Apr 96 20:22:46 GMT
- Distribution: all
- Message-ID: <829513366snz@j-bg.demon.co.uk>
- References: <DppIHL.MzF@on.bell.ca>
- Reply-To: jb@j-bg.demon.co.uk
- X-NNTP-Posting-Host: j-bg.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.29
- X-Mail2News-Path: j-bg.demon.co.uk
-
- In article <DppIHL.MzF@on.bell.ca> g2david@sprynet.com "David Leung" writes:
-
- > if I write this
- >
- > int a[10];
- > int *b1=a; <--- The pointer b points to the head of the array?
-
- b1 points to the first element of the array. that is, b1 will
- be the address of a[0]
-
-
-
- > int b2=a <--- What will we get?
-
- a compiler error.
- trying to assign an address ( that of a[0] ) to an int.
-
-
- > int b3=*a <--- what will we get?
-
- b3 will contain the contents of the first element of the array.
-
-
- > int *b4=*a <--- what will we get again?
-
- another compiler error.
- trying to assign an int to a variable meant to contain an address.
-
-
-
- > ; access like a[3]
- > int *c1;
- >
- > c1= a+3
- > cout << *c1; ?
-
- OK. you'll get the contents of c1 ( a[3] )
-
-
- > cout << c1; ?
-
- You'll get c1 ( the address of a[3] )
-
-
-
- > ; is this correct?
- > int c2;
- >
- > c2 = *(a+3); ?
- > cout << c2; ?
-
- OK. you'll get the contents of a[3]
-
-
- > ; is this correct, too?
- > int *c3
- >
- > c3 = (a + 3 * sizeof(int) );
- > count << *c3;
- >
-
- OK. you'll get the contents of a[3]
- a + 3 is the same as a + (3 * sizeof(int)) if a is an int *
-
- >
- > I am very confused!
- >
- > Can anyone explain those to me, please!
- >
- > g2david
- > :->
- >
-
-
- Regards,
- John Sargent
-